import { useCallback, useState } from 'react';

export default () => {
  const [wxLoginSwitch, setWxLoginSwitch] = useState(false);
  const [wxAppId, setWxAppId] = useState('');
  const [wxRedirectUri, setWxRedirectUri] = useState('');
  const setWxConfig = useCallback(
    (wxConfig: { ifWxLogin: boolean; wxAppId: string; wxRedirectUri: string }) => {
      setWxLoginSwitch(wxConfig.ifWxLogin);
      setWxAppId(wxConfig.wxAppId);
      let url = wxConfig.wxRedirectUri.endsWith('/')
        ? wxConfig.wxRedirectUri.slice(0, -1)
        : wxConfig.wxRedirectUri;
      setWxRedirectUri(url);
    },
    [],
  );
  return {
    wxLoginSwitch,
    wxAppId,
    wxRedirectUri,
    setWxConfig,
  };
};
